﻿// ***********************************************************************
// Apache 2.0 License
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Models
// File      : MessageAttachmentModel.cs
//
// ***********************************************************************
using ContractMeow.Api.Dtos.Attachment;

namespace ContractMeow.Models.Attachments
{
	public class MessageAttachmentModel : AttachmentModel, IMessageAttachmentModel
	{
		private string _plainTextBody;
		private Group _group;
		private User _sender;
		private long _threadId;

		internal MessageAttachmentModel()
		{
			Type = AttachmentType.Unknown;
		}

		internal MessageAttachmentModel(ContractMeow.Api.Dtos.Attachment.MessageAttachment msgAttachment)
			: base(msgAttachment)
		{
			PlainTextBody = msgAttachment.Body.Plain;
			ThreadId = msgAttachment.ThreadId;
		}

		public long ThreadId
		{
			get { return _threadId; }
			set
			{
				_threadId = value;
			}
		}

		public string PlainTextBody
		{
			get { return _plainTextBody; }
			set { _plainTextBody = value; }
		}

		public Group Group
		{
			get { return _group; }
			set
			{
				_group = value;
			}
		}

		public string GroupName
		{
			//todo: localization
			get { return Group == null ? "All company" : Group.FullName; }
		}

		public User Sender
		{
			get { return _sender; }
			set
			{
				_sender = value;
			}
		}

		public string Header
		{
			get { return string.Format("{0} posted to {1}", Sender.FullName, GroupName); }
		}

		public static IMessageAttachmentModel FromMessageAttachment(MessageAttachment msgAttachment)
		{
			return new MessageAttachmentModel(msgAttachment);
		}
	}
}